From 91f59d2041b0f2760da082827bcea57648845cc1 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Wed, 25 Jan 2017 15:10:21 +0100 Subject: [PATCH] include: speed up compat header generation Recent additions to xlat.lst have apparently resulted in Python's garbage collection getting in the way: I would guess that so far it managed to re-use previously compiled regular expressions, but with the higher number of them now can't anymore (at least with default settings). Do the compilation explicitly. While at it, combine the two lists, and avoid using re.subn() when re.sub() suffices. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- xen/tools/compat-build-source.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py index 55206e637a..595bc3ff58 100755 --- a/xen/tools/compat-build-source.py +++ b/xen/tools/compat-build-source.py @@ -12,19 +12,18 @@ pats = [ [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ], ]; -xlats = [] - xlatf = open('xlat.lst', 'r') for line in xlatf.readlines(): match = re.subn(r"^\s*\?\s+(\w*)\s.*", r"\1", line.rstrip()) if match[1]: - xlats.append(match[0]) + pats.append([ r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (match[0], match[0]), + r"\1 @KeeP@\2 \3" ]) xlatf.close() +for pat in pats: + pat[0] = re.compile(pat[0]) + for line in sys.stdin.readlines(): for pat in pats: - line = re.subn(pat[0], pat[1], line)[0] - for xlat in xlats: - line = re.subn(r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (xlat, xlat), - r"\1 @KeeP@\2 \3", line.rstrip())[0] + line = re.sub(pat[0], pat[1], line) print line.rstrip() -- 2.30.2